package cn.edu.zjicm.wordsnet_d.activity.base;

import cn.edu.zjicm.wordsnet_d.R;
import cn.edu.zjicm.wordsnet_d.util.NightModeUtil;
import android.media.AudioManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.Window;
import android.view.ViewGroup.LayoutParams;
import android.widget.RelativeLayout;

public class BaseActivity extends FragmentActivity {
	private boolean isFirstStart = true;
	private RelativeLayout baseLayout;

	// private BaseActivity mContext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		if (isFirstStart) {
			super.onCreate(savedInstanceState);
			requestWindowFeature(Window.FEATURE_NO_TITLE);
		}
		isFirstStart = false;
		setTheme(R.style.dayTimeMode);// 调用重写的setTheme方法
		super.setContentView(R.layout.layout_base);
		// 设定调整音量为媒体音量
		setVolumeControlStream(AudioManager.STREAM_MUSIC);
		findViews();
		init();
		
	}

	private void findViews() {
		baseLayout = (RelativeLayout) findViewById(R.id.base);
	}

	private void init() {

	}

	public void setContentBaseView(View view) {
		if (view != null) {
			baseLayout.addView(view, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		}
	}

	public void setContentView(int layoutId) {
		View view = getLayoutInflater().inflate(layoutId, null);
		setContentBaseView(view);
	}

	@Override
	public void setTheme(int resid) {
		switch (NightModeUtil.getDayNightMode(BaseActivity.this)) {
		case NightModeUtil.THEME_SUN:
			super.setTheme(R.style.dayTimeMode);
			break;
		case NightModeUtil.THEME_NIGHT:
			super.setTheme(R.style.nightTimeMode);
			break;
		default:
			super.setTheme(R.style.dayTimeMode);
			break;
		}
	}

	protected void resetTheme() {
		onCreate(null);
	}
}
